package com.approval.approvalapp.center.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.center.bean.MonthCommentBean;
import com.approval.approvalapp.center.bean.ThingsProductBean;
import com.approval.approvalapp.util.DensityUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 办件效率统计
 *
 * @author superman
 * @date 2019/5/9
 */
public class ThingsProductAdapter extends BaseRecycleListAdapter<ThingsProductBean> {


    public ThingsProductAdapter(List<ThingsProductBean> mList, Context context) {
        super(mList, context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.things_product_item;
    }

    @Override
    public RecyclerView.ViewHolder createHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, ThingsProductBean bean, int position) {
        if (holder instanceof ViewHolder) {
            ((ViewHolder) holder).setData(bean, position);
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_name1)
        TextView tvName1;
        @Bind(R.id.tv_name2)
        TextView tvName2;
        @Bind(R.id.tv_name3)
        TextView tvName3;
        @Bind(R.id.tv_name4)
        TextView tvName4;
        @Bind(R.id.tv_name5)
        TextView tvName5;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }


        public void setData(ThingsProductBean bean, int position) {

            tvName1.setText(bean.getNames());
            tvName2.setText(bean.getXiao_lv() +"%");
            tvName3.setText(bean.getPraiseProportion() + "%");
            tvName4.setText(bean.getSecondaryProportion() + "%");
            tvName5.setText(bean.getNegativeProportion() + "%");

            String is_xiao_lv = bean.getIs_xiao_lv();
            String is_praiseProportion = bean.getIs_PraiseProportion();
            String is_secondaryProportion = bean.getIs_SecondaryProportion();
            String is_negativeProportion = bean.getIs_NegativeProportion();

            setDrawable(Integer.valueOf(is_xiao_lv),tvName2);
            setDrawable(Integer.valueOf(is_praiseProportion),tvName3);
            setDrawable(Integer.valueOf(is_secondaryProportion),tvName4);
            setDrawable(Integer.valueOf(is_negativeProportion),tvName5);
        }

        //0平衡；1上升；2下降
        public void setDrawable(int type, TextView textView) {
            Drawable drawable;
            switch (type) {
                case 0:
                    drawable = context.getResources().getDrawable(R.drawable.efficiency_flat);
                    break;
                case 1:
                    drawable = context.getResources().getDrawable(R.drawable.efficiency_up);
                    break;
                case 2:
                    drawable = context.getResources().getDrawable(R.drawable.efficiency_down);
                    break;
                default:
                    drawable = context.getResources().getDrawable(R.drawable.efficiency_up);
                    break;
            }
            drawable.setBounds(0, 0, DensityUtil.dip2px(context,6), DensityUtil.dip2px(context,8));
            textView.setCompoundDrawablePadding(DensityUtil.dip2px(context,2));
            textView.setCompoundDrawables(null, null, drawable, null);
        }

    }
}
